package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class TravelCommend extends BaseDomain {
    public static final Integer TYPE_WEEK = 1;//周推荐
    public static final Integer TYPE_MONTH = 2;//月推荐
    public static final Integer TYPE_STRATEGY = 3;//攻略推荐

    private Travel travel; //游记攻略所关联的游记对象

    private String title;

    private String subTitle;

    private String coverUrl;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date schedule;

    private Integer type;

    public String getTypeName() {
        if (type == TYPE_WEEK) {
            return "周推荐";
        } else if (type == TYPE_MONTH) {
            return "月推荐";
        } else if(type == TYPE_STRATEGY) {
            return "攻略推荐";
        }

        return "";
    }

    public String getJSONString(){
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("id",id );
        map.put("title",title );
        map.put("subTitle",subTitle );
        map.put("coverUrl",coverUrl );
        map.put("schedule", DateUtil.formatDate(schedule));
        map.put("type",type );

        if(travel!=null){
            map.put("travelId",travel.getId() );
        }
        return JSONUtils.toJSONString(map);

    }

}